package xuegao.study.mall.web.ms;

import com.alibaba.fastjson.JSON;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import xuegao.study.mall.common.ms.SeckillOrder;

@Component
public class SeckillListener {

    private Logger logger = LoggerFactory.getLogger(SeckillListener.class);

    @Autowired
    private SeckillService seckillService;

    @RabbitListener(queues = "seckill.order")
    public void receiveMessage(String message) {
        logger.info("接收到秒杀订单的信息,生成订单->"+message);
        SeckillOrder order = JSON.parseObject(message, SeckillOrder.class);
        seckillService.createOrder(order);
    }
}

